package com.lq.createPattern.singleton.type4;

public class SingletonTest04 {
    public static void main(String[] args) {
        System.out.println("懒汉式 线程安全写法 解决线程同步问题但是效率不行");
        Singleton singleton = Singleton.getInstance();
        Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton1 == singleton);
        System.out.println(singleton1.hashCode());
        System.out.println(singleton.hashCode());
    }
}
class Singleton{
    private Singleton() {};
    private static Singleton instance;

    public static synchronized Singleton getInstance() {
        if(null==instance){
            instance=new Singleton();
        }
        return instance;
    }
}